'''
Author: Jackiu
Date: 2021-05-07 18:19:36
LastEditors: Jackiu
LastEditTime: 2021-05-07 18:53:07
Description: file content
'''
import sys
import os

# 读取配置名称并设置工作目录
config_path = sys.argv[1]
config_name = config_path.split('/')[-1].replace('.py', '')
workdir = f"./work_dirs/{config_name}"
for i in range(100):
    if not os.path.exists(f"{workdir}/exp{i}"):
        workdir = f"{workdir}/exp{i-1 if len(sys.argv) >= 4 else i}"
        break

# 设置执行命令
excute_command = f"CUDA_VISIBLE_DEVICES={sys.argv[2] if len(sys.argv) >= 3 else 3} "
excute_command += "python ./tools/train.py "
excute_command += f"--seed 0 "
excute_command += f"--work-dir {workdir} "
excute_command += f"--resume-from {sys.argv[3]} " if len(sys.argv) >= 4 else ""
excute_command += config_path

print(workdir)
print(excute_command)

os.system(excute_command)